home *** CD-ROM | disk | FTP | other *** search
/ Palm Utilities / Palm_Utilities_CD-ROM_2001_2001.iso / files / misc / B.O.F.H Excuse Calendar 1.0 / bofh.exe / bofh.c next >
Encoding:
C/C++ Source or Header  |  1999-07-09  |  17.0 KB  |  551 lines

  1. /*************************************************************************
  2. * The Unoffical Bastard Operator From Hell (B.O.F.H.)
  3. * Excuse Calendar V1.1
  4. *
  5. * (c) 1999 Robert Carr
  6. *     rob@itsproven.com
  7. *     www.itsproven.com
  8. * This program is FREEWARE. Linux Rules.
  9. *
  10. * if you use the source, or the program, drop me a note.  If have
  11. * written your own pilot program, include the source so others may learn
  12. * from your code.
  13. *
  14. * ---late
  15. ************************************************************************/
  16.  
  17.  
  18. #include "bofh.rsh"
  19. #include <System/SysAll.h>
  20. #include <UI/UIAll.h>
  21.  
  22. #define    TOTALEXCUSES    248  
  23. #define MESSAGE_AT_Y    60 // Y position to start displaying messages
  24. #define WORD_WRAP_AT    140 // # of pixels to wrap text at
  25.  
  26. #define appCreatorID    'Bofh'
  27. #define appPrefID    0x00
  28.  
  29. DateType today;
  30. ULong     secs;
  31.  
  32.  
  33. typedef struct {
  34.         Word    day;
  35.         int    version;
  36.         Word     lastExcuse;
  37. } prefs;
  38.     
  39. prefs myprefs;
  40.  
  41. static void EventLoop(void);
  42. static void StartApplication(void);
  43. static void StopApplication(void);
  44. static void DisplayNewExcuse(void);
  45. static void CheckDatabases(void);
  46. static void readPreferences(void);
  47. static void chopper(void *source, void *dest);
  48.  
  49. static Boolean MainMenuHandler(EventPtr event);
  50. static Boolean MainFormHandleEvent(EventPtr event);
  51.  
  52. char line1[80];
  53. char line2[80];
  54. char line3[80];
  55.  
  56. char *pline1 = line1;
  57. char *pline2 = line2;
  58. char *pline3 = line3;
  59. char *pExcuse;
  60.  
  61. // all the excuses.  I think I should throw these into a separate PDB file.
  62. // oh well...next version.
  63.  
  64. char excuses[TOTALEXCUSES][100] = { 
  65.  
  66. "Clock speed", 
  67. "Solar flares", 
  68. "Electromagnetic radiation from satellite debris", 
  69. "Global warming", 
  70. "Poor power conditioning", 
  71. "Static buildup",
  72. "Doppler effect", 
  73. "Hardware stress fractures", 
  74. "Magnetic interference from money/credit cards", 
  75. "Dry joints on cable plug", 
  76. "We're waiting for [the phone company] to fix that line", 
  77. "Sounds like a Windows problem, try calling Microsoft support", 
  78. "Temporary routing anomaly", 
  79. "Somebody was calculating pi on the server", 
  80. "Fat electrons in the lines", 
  81. "Excess surge protection", 
  82. "Floating point processor overflow", 
  83. "Divide-by-zero error", 
  84. "POSIX compliance problem", 
  85. "Monitor resolution too high", 
  86. "Improperly oriented keyboard", 
  87. "Network packets travelling uphill", 
  88. "Decreasing electron flux", 
  89. "radiosity depletion", 
  90. "CPU radiator broken", 
  91. "It works the way the Wang did, what's the problem", 
  92. "Positron router malfunction", 
  93. "Cellular telephone interference", 
  94. "Tectonic stress", 
  95. "piezo-electric interference", 
  96. "(l)user error", 
  97. "Working as designed", 
  98. "Dynamic software linking table corrupted", 
  99. "Heavy gravity fluctuation, move computer to floor rapidly", 
  100. "Secretary plugged hairdryer into UPS", 
  101. "Terrorist activities", 
  102. "Not enough memory, go get system upgrade", 
  103. "Interrupt configuration error", 
  104. "Spaghetti cable cause packet failure", 
  105. "Boss forgot system password", 
  106. "Bank holiday - system operating credits not recharged", 
  107. "Virus attack, luser responsible", 
  108. "Complete Transient Lockout", 
  109. "Bad ether in the cables", 
  110. "Bogon emissions", 
  111. "Change in Earth's rotational speed", 
  112. "Cosmic ray particles crashed through the hard disk platter", 
  113. "Groundskeepers stole the root password", 
  114. "High pressure system failure", 
  115. "Failed trials, system needs redesigned", 
  116. "System has been recalled", 
  117. "Not approved by the FCC", 
  118. "Need to wrap system in aluminum foil to fix problem", 
  119. "Not properly grounded, please bury computer", 
  120. "CPU needs recalibration", 
  121. "System needs to be rebooted", 
  122. "Bit bucket overflow", 
  123. "Descramble code needed from software company", 
  124. "Only available on a need to know basis", 
  125. "Knot in cables caused data stream to become twisted and kinked", 
  126. "Nesting roaches shorted out the ether cable", 
  127. "The file system is full of it", 
  128. "Daemons did it", 
  129. "You're out of memory", 
  130. "There isn't any problem", 
  131. "Unoptimized hard drive", 
  132. "Typo in the code", 
  133. "Yes, yes, its called a design limitation", 
  134. "Look, buddy: Windows 3.1 IS A General Protection Fault.", 
  135. "Support staff hung over, send aspirin and come back LATER.", 
  136. "Someone is standing on the Ethernet cable, causing a kink in the cable", 
  137. "Windows 95 \"feature\"", 
  138. "Runt packets", 
  139. "Password is too complex to decrypt", 
  140. "Electromagnetic energy loss", 
  141. "Budget cuts", 
  142. "Mouse chewed through power cable", 
  143. "Stale file handle", 
  144. "Feature not yet implemented", 
  145. "Internet outage", 
  146. "Pentium FDIV bug", 
  147. "Vendor no longer supports the product", 
  148. "The vendor put the bug there.", 
  149. "SIMM crosstalk.", 
  150. "IRQ dropout", 
  151. "Collapsed Backbone", 
  152. "Power company testing new voltage spike (creation) equipment", 
  153. "Operators on strike due to broken coffee machine", 
  154. "Backup tape overwritten with copy of system manager's favorite CD", 
  155. "UPS interrupted the server's power", 
  156. "The keyboard isn't plugged in", 
  157. "The air conditioning water supply pipe ruptured over the machine room", 
  158. "Root name servers are out of sync", 
  159. "Electro-magnetic pulses from French above ground nuke testing.", 
  160. "Your keyboard's space bar is generating spurious keycodes.", 
  161. "The real TTY's became pseudo TTY's and vice-versa.", 
  162. "The printer thinks its a router.", 
  163. "The router thinks its a printer.", 
  164. "Evil hackers from Serbia.", 
  165. "We just switched to FDDI.", 
  166. "User to computer ratio too high.", 
  167. "User to computer ration too low.", 
  168. "We just switched to Sprint.", 
  169. "Sticky bits on disk." 
  170. "Power Company having EMP problems with their reactor", 
  171. "The ring needs another token", 
  172. "new management", 
  173. "Telnet: Unable to connect to remote host: Connection refused", 
  174. "SCSI Chain over-terminated", 
  175. "It's not plugged in.", 
  176. "Because of network lag due to too many people playing deathmatch", 
  177. "You put the disk in upside down.", 
  178. "Daemons loose in system.", 
  179. "User was distributing pornography on server; system seized by FBI.", 
  180. "Disks spinning backwards - toggle the hemisphere jumper.", 
  181. "New guy cross-connected phone lines with ac power bus.", 
  182. "Had to use hammer to free stuck disk drive heads.", 
  183. "Too few computrons available.", 
  184. "Communications satellite used by the military for star wars.", 
  185. "Party-bug in the Aloha protocol.", 
  186. "Dew on the telephone lines.", 
  187. "Arcserve crashed the server again.", 
  188. "Some one needed the powerstrip, so they pulled the switch plug.", 
  189. "Big to little endian conversion error", 
  190. "Dumb terminal", 
  191. "Zombie processes haunting the computer", 
  192. "Incorrect time synchronization", 
  193. "Defunct processes", 
  194. "Stubborn processes", 
  195. "Non-redundant fan failure ", 
  196. "Monitor VLF leakage", 
  197. "Bugs in the RAID", 
  198. "Root rot", 
  199. "Backbone Scoliosis", 
  200. "Excessive collisions & not enough packet ambulances", 
  201. "le0: no carrier: transceiver cable problem?", 
  202. "Broadcast packets on wrong frequency", 
  203. "Popper unable to process jumbo kernel", 
  204. "NOTICE: alloc: /dev/null: filesystem full", 
  205. "Pseudo-user on a pseudo-terminal", 
  206. "Recursive traversal of loopback mount points", 
  207. "Backbone adjustment", 
  208. "OS swapped to disk", 
  209. "sticktion", 
  210. "Short leg on process table", 
  211. "Multicasts on broken packets", 
  212. "Ether leak", 
  213. "endothermal recalibration", 
  214. "filesystem not big enough for Jumbo Kernel Patch", 
  215. "Loop found in loop in redundant loopback", 
  216. "System consumed all the paper for paging", 
  217. "Permission denied", 
  218. "..Disk or the processor is on fire.", 
  219. "SCSI's too wide.", 
  220. "Proprietary Information.", 
  221. "Just type \'mv * /dev/null\'.", 
  222. "Runaway cat on system.", 
  223. "Did you pay the new Support Fee?", 
  224. "We only support a 1200 BPS connection.", 
  225. "We only support a 28000 BPS connection.", 
  226. "The curls in your keyboard cord are losing electricity.", 
  227. "The monitor needs another box of pixels.", 
  228. "RPC_PMAP_FAILURE", 
  229. "kernel panic: write-only-memory (/dev/wom0) capacity exceeded.", 
  230. "Quantum dynamics are affecting the transistors", 
  231. "Your mail is being routed through Germany ... and they're censoring us.", 
  232. "Only people with names beginning with \'A\' are getting mail this week", 
  233. "We didn't pay the Internet bill and it's been cut off." ,
  234. "Lightning strikes.", 
  235. "Of course it doesn't work. We've performed a software upgrade.", 
  236. "Change your language to Finnish.", 
  237. "High nuclear activity in your area.", 
  238. "The UPS doesn't have a battery backup.", 
  239. "Recursivity.  Call back if it happens again.", 
  240. "Someone thought The Big Red Button was a light switch.", 
  241. "The mainframe needs to rest.  It's getting old, you know.", 
  242. "I'm not sure.  Try calling the Internet's head office -- it's in the book.", 
  243. "A star wars satellite accidentally blew up the WAN.", 
  244. "Fatal error right in front of screen", 
  245. "Wrong polarity of neutron flow", 
  246. "Lusers learning curve appears to be fractal", 
  247. "We had to turn off that service to comply with the CDA Bill.", 
  248. "Ionization from the air-conditioning", 
  249. "TCP/IP UDP alarm threshold is set too low.", 
  250. "Someone is broadcasting pigmy packets and the router doesn't know how to deal with them.", 
  251. "The new frame relay network hasn't bedded down the software loop transmitter yet. ", 
  252. "Fanout dropping voltage too much, try cutting some of those little traces", 
  253. "Plate voltage too low on demodulator tube", 
  254. "You did wha... oh _dear_....", 
  255. "CPU needs bearings repacked", 
  256. "Too many little pins on CPU confusing it, bend back and forth until 10-20% are \"neatly removed.\"", 
  257. "_Rosin_ core solder? But...", 
  258. "Software uses US measurements, but the OS is in metric...", 
  259. "Too much radiation coming from the soil.", 
  260. "Program load too heavy for processor to lift.", 
  261. "Processes running slowly due to weak power supply", 
  262. "We've run out of licenses", 
  263. "Interference from lunar radiation", 
  264. "Standing room only on the bus.", 
  265. "You need to install an RTFM interface.", 
  266. "That would be because the software doesn't work.", 
  267. "That's easy to fix, but I can't be bothered.", 
  268. "We're upgrading /dev/null", 
  269. "The Usenet news is out of date", 
  270. "Our POP server was kidnapped by a weasel.", 
  271. "It's stuck in the Web.", 
  272. "Your modem doesn't speak English.", 
  273. "All of the packets are empty.", 
  274. "The UPS is on strike.", 
  275. "Neutrino overload on the nameserver", 
  276. "Melting hard drives", 
  277. "Someone has messed up the kernel pointers", 
  278. "The kernel license has expired", 
  279. "It was OK before you touched it.", 
  280. "Bit rot", 
  281. "The static electricity routing is acting up...", 
  282. "Traceroute says that there is a routing problem in the backbone.  It's not our problem.", 
  283. "The co-locator cannot verify the frame-relay gateway to the ISDN server.", 
  284. "Electrons on a bender", 
  285. "Telecommunications is upgrading. ", 
  286. "Telecommunications is downgrading.", 
  287. "Telecommunications is downshifting.", 
  288. "Hard drive sleeping. Let it wake up on it's own...", 
  289. "Interference between the keyboard and the chair.", 
  290. "The CPU has shifted, and become decentralized.", 
  291. "Due to the CDA, we no longer have a root account.", 
  292. "You must've hit the wrong anykey.", 
  293. "PCMCIA slave driver", 
  294. "The Token fell out of the ring. Call us when you find it.", 
  295. "The hardware bus needs a new token.", 
  296. "Too many interrupts", 
  297. "Not enough interrupts", 
  298. "The data on your hard drive is out of balance.", 
  299. "Digital Manipulator exceeding velocity parameters", 
  300. "Appears to be a Slow/Narrow SCSI-0 Interface problem", 
  301. "microelectronic Riemannian curved-space fault in write-only file system", 
  302. "Fractal radiation jamming the backbone", 
  303. "Routing problems on the neural net", 
  304. "IRQ-problems with the Un-Interruptable-Power-Supply", 
  305. "CPU-angle has to be adjusted because of vibrations coming from the nearby road", 
  306. "Emissions from GSM-phones", 
  307. "CD-ROM server needs recalibration", 
  308. "Firewall needs cooling", 
  309. "Asynchronous inode failure", 
  310. "Transient bus protocol violation", 
  311. "Incompatible bit-registration operators", 
  312. "Your process is not ISO 9000 compliant", 
  313. "You need to upgrade your VESA local bus to a MasterCard local bus.", 
  314. "The recent proliferation of Nuclear Testing", 
  315.  
  316.             };
  317.  
  318.  
  319. int  intCurrentExcuse;
  320.  
  321. /********************************************************************
  322. * Basic PilotMain stuff here.
  323. *
  324. ********************************************************************/
  325.  
  326. DWord PilotMain (Word cmd, Ptr cmdPBP, Word launchFlags) {
  327.  
  328.  
  329.     if (cmd == sysAppLaunchCmdNormalLaunch) {
  330.  
  331.     StartApplication();
  332.     EventLoop();
  333.     StopApplication();
  334.  
  335.     }
  336.  
  337. return 0;
  338.  
  339. }
  340.  
  341. /****************************************************************
  342. * Event Loop Handler
  343. *
  344. ****************************************************************/
  345.  
  346. static void EventLoop(void) {
  347.     
  348.     EventType event;    
  349.     Word error;
  350.     
  351.     
  352.     do {
  353.     
  354.     EvtGetEvent(&event, evtWaitForever);
  355.     
  356.  
  357.     if (!SysHandleEvent(&event)) {
  358.  
  359.         if (!MenuHandleEvent(NULL, &event, &error)) {
  360.     
  361.                 if (!MainFormHandleEvent(&event)) {
  362.             
  363.                     if (!FrmHandleEvent(FrmGetActiveForm(), &event));
  364.                 }
  365.         }
  366.     }
  367.  
  368.     } while (event.eType != appStopEvent);
  369.  
  370. }
  371.     
  372.  
  373. /*******************************************************************************
  374. * Stop application and save the date and current excuse for later.
  375. *
  376. *******************************************************************************/
  377.     
  378. static void StopApplication() {
  379.  
  380. prefs mypref;
  381.  
  382. mypref.lastExcuse = intCurrentExcuse;
  383. mypref.version = 1;
  384. mypref.day = today.day;
  385.  
  386. PrefSetAppPreferencesV10(appCreatorID, appPrefID, &mypref, sizeof(mypref));
  387.  
  388.  
  389. }
  390.     
  391. /******************************************************************************
  392. * Start Application and display main form.  Also checks preferences.
  393. *
  394. ******************************************************************************/
  395.  
  396. static void StartApplication() {
  397.  
  398.     FormPtr    frm;    
  399.  
  400.     secs = TimGetSeconds();
  401.     DateSecondsToDate(secs, &today);
  402.     readPreferences();
  403.     
  404.     frm = FrmInitForm(formID_main);
  405.     FrmSetActiveForm(frm);
  406.     FrmDrawForm(frm);
  407.     DisplayNewExcuse();
  408.  
  409. }
  410.  
  411. /*******************************************************************************
  412. * Main form handler.
  413. *
  414. *******************************************************************************/
  415. static Boolean MainFormHandleEvent(EventPtr event) {
  416.  
  417.  
  418. Boolean handled = false;
  419. FormPtr     form;
  420.         
  421.  
  422.         switch (event->eType) {
  423.  
  424.         case ctlEnterEvent:
  425.     
  426.             if (event->data.ctlEnter.controlID == buttonID_newexcuse) {
  427.                 handled = true;
  428.                 ++intCurrentExcuse;
  429.                 DisplayNewExcuse();
  430.                 break;
  431.             }
  432.  
  433.         case menuEvent:
  434.         
  435.         if (event->data.menu.itemID == menuitemID_about) {
  436.             handled = true;
  437.             FrmAlert(alertID_about);
  438.             break;    
  439.         }
  440.             
  441.         
  442.     }
  443.         
  444. return handled;
  445. }
  446.  
  447. /*************************************************************************
  448. *
  449. * Display an excuse from array using intCurrentExcuse as the index.
  450. * Splits string if too wide to display.
  451. *
  452. *************************************************************************/
  453.  
  454. static void DisplayNewExcuse() {
  455.     
  456.         
  457.     RectangleType rect; 
  458.     int center;
  459.     
  460.  
  461.     if (intCurrentExcuse > TOTALEXCUSES) { intCurrentExcuse = 0; } 
  462.  
  463.     StrCopy(pline1, excuses[intCurrentExcuse]);
  464.  
  465.     chopper(line1, line2);
  466.     chopper(line2, line3);
  467.  
  468.     rect.extent.x = 160; rect.extent.y = MESSAGE_AT_Y+20;
  469.     rect.topLeft.x = 0; rect.topLeft.y = MESSAGE_AT_Y;
  470.     
  471.     WinEraseRectangle(&rect, 0);  
  472.  
  473.         center = ((160-FntCharsWidth(line1, StrLen(line1)))/2);
  474.         WinDrawChars(line1, StrLen(line1) , center , MESSAGE_AT_Y);
  475.     
  476.     if (line2) {     
  477.         int center = ((160-FntCharsWidth(line2, StrLen(line2)))/2);
  478.         WinDrawChars(line2, StrLen(line2), center, MESSAGE_AT_Y+10); }
  479.  
  480.     if (line3) {
  481.         int center = ((160-FntCharsWidth(line3, StrLen(line3)))/2);
  482.          WinDrawChars(line3, StrLen(line3), center, MESSAGE_AT_Y+20);
  483.     }
  484.  
  485.     *pline1 = '\0';
  486.     *pline2 = '\0';
  487.     *pline3 = '\0';
  488. }
  489.  
  490.  
  491. /*********************************************************************************
  492. * Checks to see if user has run application before.  If not, display
  493. * proram info and set prefs.
  494. *
  495. * Also checks to see if the date has changed, if so it displays a new message.
  496. *********************************************************************************/
  497.  
  498. void readPreferences (void) {
  499.  
  500.  
  501.     if (!PrefGetAppPreferencesV10(appCreatorID, appPrefID, &myprefs, sizeof(prefs))) {
  502.  
  503.     FrmAlert(alertID_about);
  504.  
  505.     myprefs.lastExcuse = intCurrentExcuse = SysRandom(0)%TOTALEXCUSES;
  506.     myprefs.version = 1;
  507.     myprefs.day = today.day;
  508.  
  509.     PrefSetAppPreferencesV10(appCreatorID, appPrefID, &myprefs, sizeof(prefs));
  510.     
  511.     }
  512.     
  513.     else
  514.      {
  515.         PrefGetAppPreferencesV10(appCreatorID, appPrefID, &myprefs, sizeof(prefs));
  516.         intCurrentExcuse = myprefs.lastExcuse;
  517.         if (myprefs.day != today.day) {
  518.             intCurrentExcuse++;
  519.         }
  520.     }
  521.  
  522. }
  523.  
  524. /********************************************************************************
  525. * checks source string to see if it needs to be word wrapped.  If so, it copies
  526. * remaining chars to *dest string. 
  527. *
  528. *********************************************************************************/
  529.  
  530. void chopper (void *source, void *dest) {
  531.  
  532. char *myDest = dest;
  533. char *mySource = source;
  534. int i =0;    
  535.  
  536.     if (StrLen(source) > FntWordWrap(source, WORD_WRAP_AT)) {
  537.     
  538.         i = FntWordWrap(source, WORD_WRAP_AT);
  539.             do {
  540.             *myDest++ = *(mySource+i);
  541.             i++;
  542.         } while (i < StrLen(source));
  543.     
  544.         *(mySource+FntWordWrap(source, WORD_WRAP_AT)) = '\0';
  545.         *myDest = '\0';
  546.     }
  547.  
  548. }
  549.  
  550.